package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity{

//    private Button btn2 = null;
    private Button btn3 = null;
    private Button btn4 = null;

    private List<To> toList = new ArrayList<To>();
//    private String[] data = {"HelloWorld","Hello","World"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        this.btn2 = (Button) super.findViewById(R.id.btn2);
        this.btn3 = (Button) super.findViewById(R.id.btn3);
        this.btn4 = (Button) super.findViewById(R.id.btn4);

//        this.btn2.setOnClickListener(new OnClickListenerImplLong());
        this.btn3.setOnClickListener(new OnClickListenerImplShort());
        this.btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,FrameActivity.class);
                startActivity(intent);
            }
        });

        initTo();
        ToAdapter adapter = new ToAdapter(MainActivity.this,R.layout.to_item,toList);
//        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
//                MainActivity.this, android.R.layout.simple_list_item_1, data);
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListenerShort());
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AlertDialog alertDialog1 = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("Helloworld")//标题
                        .setMessage("welcome to China ,HelloWorld!!!")//内容
                        .setIcon(R.mipmap.ic_launcher)//图标
                        .create();
                alertDialog1.show();
            }
        });


    }

    private void initTo() {
        To A = new To("Hello world");
        toList.add(A);
        To B = new To("Hello");
        toList.add(B);
        To C = new To("world");
        toList.add(C);

    }

    public void Btn1(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,HelloActivity.class);
        startActivity(intent);
    }

    public void Btn2(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,GridActivity.class);
        startActivity(intent);
    }

    public void Btn5(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,TableActivity.class);
        startActivity(intent);
    }

    public void Btn6(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,AbsoluteActivity.class);
        startActivity(intent);
    }

    public void Btn7(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,ImageActivity.class);
        startActivity(intent);
    }
    public void Btn8(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,LoginActivity.class);
        startActivity(intent);
    }
    public void Btn9(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,CameraActivity.class);
        startActivity(intent);
    }

    public void Btn10(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,SettingActivity.class);
        startActivity(intent);
    }

    public void Btn11(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,FrameAnimActivity.class);
        startActivity(intent);
    }
    public void Btn12(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,FrameAnim2Activity.class);
        startActivity(intent);
    }

    public void Btn13(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,TweenAnimActivity.class);
        startActivity(intent);
    }
    public void Btn14(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,PropertyActivity.class);
        startActivity(intent);
    }

//    private class OnClickListenerImplLong implements View.OnClickListener{
//        public void onClick(View v){
//            Toast.makeText(MainActivity.this,"Hello World!",Toast.LENGTH_LONG).show();
//        }
//    }
    private class OnClickListenerImplShort implements View.OnClickListener{
        public void onClick(View v){
            Toast.makeText(MainActivity.this,"HelloWorld!!!",Toast.LENGTH_SHORT).show();
        }
    }

    private  class OnItemClickListenerShort  implements AdapterView.OnItemClickListener{
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Toast.makeText(MainActivity.this,"HelloWorld!!!",Toast.LENGTH_SHORT).show();
        }
    }



}